package com.smmisia.auth.controller;

import com.smmisia.common.request.auth.MenuRequest;
import com.smmisia.auth.service.SysMenuService;
import com.smmisia.common.Result.Result;
import com.smmisia.common.entity.auth.SysMenu;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: smmisia
 * @date: 2023-09-08
 * @description: 菜单管理
 */
@RestController
@RequestMapping("/menu")
@Slf4j
@Tag(name = "菜单管理")
public class MenuController {

    @Autowired
    private SysMenuService sysMenuService;

    /**
     * 添加菜单
     *
     * @param menuRequest
     * @return
     */
    @PostMapping("/add")
    @Operation(summary = "添加菜单", description = "添加菜单")
    public Result<String> addRole(@Valid @RequestBody MenuRequest menuRequest) {
        return sysMenuService.addMenu(menuRequest);
    }

    /**
     * 删除菜单
     *
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public Result<String> deleteMenu(@RequestParam(name = "id") @NotNull(message = "id不能为空") Integer id) {
        return sysMenuService.deleteMenu(id);
    }

    /**
     * 修改菜单
     *
     * @param menuRequest
     * @return
     */
    @PostMapping("/update")
    public Result<String> updateMenu(@Valid @RequestBody MenuRequest menuRequest) {
        return sysMenuService.updateMenu(menuRequest);
    }

    /**
     * 获取菜单列表
     *
     * @return
     */
    @GetMapping("/list")
    public Result<List<SysMenu>> menuList(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                          @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        return sysMenuService.getMenu(pageNum, pageSize);
    }

    /**
     * 获取菜单信息
     *
     * @param id
     * @return
     */

    @GetMapping("/info")
    public Result<SysMenu> getMenu(@RequestParam(name = "id") @NotNull(message = "id不能为空") Integer id) {
        return sysMenuService.getMenuInfo(id);

    }
}